launch an app SMART on Fhir app from medplum which will fetch only that patient data from which we have launch the app.the app should also fetch related resources like condition,medicationrequest,observation,risk assesment,care plan,cds alert from that perticular patient and it should calculate risk assesment from the resource data ..build such app using .net core as backend nd css javascript html as frontend ,and oauth2.0 as authentication system

Copilot said:
Yes. This is a very common SMART on FHIR clinical application pattern.

Solution Overview
Build a SMART on FHIR Patient Context App that launches from Medplum and automatically receives the currently selected patient context.

Features
✅ SMART on FHIR Launch from Medplum

✅ OAuth2.0 + OpenID Connect Authentication

✅ Fetch only launch patient data

✅ Fetch related resources:

Patient
Condition
Observation
MedicationRequest
CarePlan
RiskAssessment
DetectedIssue (CDS Alerts)
AllergyIntolerance
Encounter
✅ Calculate Clinical Risk Score

✅ Display Patient Dashboard

✅ .NET 8 Backend API

✅ HTML + CSS + JavaScript Frontend

✅ PostgreSQL Database

✅ FHIR R4 Compatible

Architecture



Plain Text
+-------------------+
| Medplum FHIR      |
| Server            |
+---------+---------+
          |
          |
 SMART Launch
 OAuth2
          |
          v
+-------------------+
| SMART App         |
| Frontend          |
| HTML CSS JS       |
+---------+---------+
          |
          |
 JWT Token
 Patient Context
          |
          v
+-------------------+
| ASP.NET Core API  |
| Backend           |
+---------+---------+
          |
          |
 FHIR API Calls
          |
          v
+-------------------+
| Medplum FHIR      |
+-------------------+

Show more lines
SMART Launch Flow
Step 1
User opens patient in Medplum

Example:




Plain Text
Patient: Priyanka Sankpal
Step 2
Clicks




Plain Text
Launch SMART App
Step 3
Medplum sends




Plain Text
launch=abc123
 
iss=https://api.medplum.com/fhir/R4
Step 4
App redirects user to authentication




Plain Text
authorize endpoint
Step 5
Obtain




JSON
{
  "access_token":"xxxxx",
  "patient":"12345"
}
Patient ID automatically comes from SMART launch.

OAuth 2.0 Configuration
SMART Scopes



Plain Text
launch
 
openid
 
profile
 
fhirUser
 
patient/*.read
 
offline_access
Backend Structure



Plain Text
ClinicalInsightsPro.API
 
├── Controllers
│   └── SmartController.cs
 
├── Services
│   ├── SmartLaunchService.cs
│   ├── FhirService.cs
│   └── RiskAssessmentService.cs
 
├── Models
│   ├── PatientDto.cs
│   ├── ObservationDto.cs
│   ├── ConditionDto.cs
│   └── RiskScoreDto.cs
 
├── Data
│   └── AppDbContext.cs

Show more lines
API Endpoint



C#
GET /api/smart/dashboard/{patientId}
Response:




JSON
{
  "patient": {},
  "conditions": [],
  "medicationRequests": [],
  "observations": [],
  "carePlans": [],
  "riskAssessment": {},
  "cdsAlerts": []
}
FHIR Queries
Patient



HTTP
GET Patient/{patientId}
Conditions



HTTP
GET Condition?patient={patientId}
Observations



HTTP
GET Observation?patient={patientId}
MedicationRequest



HTTP
GET MedicationRequest?patient={patientId}
CarePlan



HTTP
GET CarePlan?patient={patientId}
RiskAssessment



HTTP
GET RiskAssessment?patient={patientId}
CDS Alerts



HTTP
GET DetectedIssue?patient={patientId}
Dashboard Aggregated Query
Use one FHIR bundle request:




HTTP
GET Patient/{id}/$everything
This returns:




Plain Text
Patient
Condition
Observation
MedicationRequest
CarePlan
Encounter
AllergyIntolerance
Procedure
DiagnosticReport
and is much faster.